package com.service;

import java.util.List;
import com.dao.CommentDao;
import com.dao.ContactDao;
import com.entity.Comment;
import com.entity.Contact;
import com.entity.UserProject;
import com.util.DateHelp;
import com.util.UUIDHelp;

public class ContactService {

	private static ContactDao cd = new ContactDao();
	private static CommentDao cod = new CommentDao();
	
	public List<Contact> findAllContact(String projectid) {
		return cd.findAllContact(projectid);
	}
	
	public List<Comment> findAllCommentFromContact(){
		return cod.findAllCommenttoContact();
	}
	
	public void saveContcat(String name, String company, String phone,
			String tel, String email, String address, String home,
			String weibo, String adstruct, String projectid) {
		Contact c=new Contact();
		c.setAddress(address);
		c.setAdstruct(adstruct);
		c.setCompany(company);
		c.setEmail(email);
		c.setHome(home);
		c.setCreatetime(DateHelp.getTime());
		c.setId(UUIDHelp.executeUUID());
		c.setTel(tel);
		c.setName(name);
		c.setPhone(phone);
		c.setWeibo(weibo);
		c.setProjectid(projectid);
		
		cd.save(c);
	}

	public Contact findContactById(String id) {
		return cd.findContactById(id);	
	}

	public void updateContcat(String name, String company, String phone,
			String tel, String email, String address, String home,
			String weibo, String adstruct, String id) {
		Contact c=new Contact();
		c.setAddress(address);
		c.setAdstruct(adstruct);
		c.setCompany(company);
		c.setEmail(email);
		c.setHome(home);
		c.setTel(tel);
		c.setName(name);
		c.setPhone(phone);
		c.setWeibo(weibo);
		c.setId(id);	
		cd.update(c);
	}

	public void delById(String id) {
		cd.delById(id);
	}

	public void saveRecord(String record, String contactid, UserProject up) {
		Comment co=new Comment();
		co.setId(UUIDHelp.executeUUID());
		co.setContactid(contactid);
		co.setCreateTime(DateHelp.getTime());
		co.setMessage(record);
		co.setUserid(up.getUserid());
		
		cod.saveFormContact(co);
		
	}


}
